package com.gsta.cdn.cdr.controller;

import com.gsta.cdn.cdr.entity.ResultEntity;
import com.gsta.cdn.cdr.mapper.CIDConcurrentMapper;
import com.gsta.cdn.cdr.mapper.ConcurrentMapper;
import com.gsta.cdn.cdr.service.CIDConcurrentService;
import com.gsta.cdn.cdr.service.ConcurrentService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletResponse;
import java.util.List;
import java.util.Map;

@Controller
@RequestMapping(path = "/CIDConcurrent")
public class CIDConcurrentController {
    @Autowired
    private CIDConcurrentMapper cidConcurrentMapper;

    @Resource
    private CIDConcurrentService cidConcurrentService;

    //并发统计
    @RequestMapping(path = "/All", method = RequestMethod.POST)
    @ResponseBody
    public ResultEntity ChannelConcurrent(@RequestParam(required = true) String date,
                                          @RequestParam(required = true) String cid,
                                          HttpServletResponse response) {

        response.setHeader("Access-Control-Allow-Origin","*");
        response.setHeader("Cache-Control","no-cache");
        List<Map<String, Object>> list = cidConcurrentService.CIDConcurrentAll(date,cid);
//        List<Map<String, Object>> vodlist = concurrentMapper.VodConcurrent(date);
//        list.addAll(vodlist);
        ResultEntity resultEntity = new ResultEntity();
        try {
            resultEntity.setData(list);
//            resultEntity.setData(vodlist);
            if (list.size() > 0){
                resultEntity.setMsg("查询成功");
                resultEntity.setCode(0);
            }else{
                resultEntity.setMsg("无数据");
                resultEntity.setCode(-1);
            }
            return resultEntity;
        }
        catch (Exception e){
            return ResultEntity.error("查询失败");
        }
    }
}
